<?php
/**
 * @purpose: 对“通知”类型中子类型为7(X是你游戏中的好友，系统已经把Ta自动加为你的好友啦)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: 参阅母板文件
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type7_encoder() {
	$fields = array("friend_sdid");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	return $friend_sdid;
}

function msg_notice_type7_decoder() {
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$friend_sdid = $content;
	$users_infos = UCModUserInfo::getUserInfos(array($friend_sdid), array(USERINFO_NICKNAME, USERINFO_GENDER));

	$nickname = htmlspecialchars($users_infos[$friend_sdid][USERINFO_NICKNAME]);
	$nickname == '' && $nickname = $friend_sdid;

	$friend_url  = get_user_home_url($friend_sdid);
	$friend_link = "<a href=\"{$friend_url}\" target='_blank'>{$nickname}</a>";

	$gender = $users_infos[$friend_sdid][USERINFO_GENDER] == 1 ? '他' : '她';


	if ($fmt == 'line') {
		return sprintf("%s是你游戏中的好友，系统已经把%s自动加为你的好友啦", $friend_link, $gender);





	} else if ($fmt == 'box') {
		require_once(dirname(__FILE__)."/../../../models/store/UCModPanel.php");
		require_once(dirname(__FILE__)."/../../../models/store/UCModStore.php");

		$share_apps = UCModStore::getInstance()->getShareAppFromUser1AndUser2($receiverid, $friend_sdid, 10);
		#$share_apps = UCModStore::getInstance()->getShareAppFromUser1AndUser2(1000, 1109332811, 10);
		!is_array($share_apps) && $share_apps = array();

		$app_list = "";
		foreach($share_apps as $app) {
			$icon = UCModPanel::getIcon($app['id'], '50');
			$app_list .= sprintf('<a href="%s" target="_blank"><img src="%s" /><br />%s</a>',
								$app['link'],
								$icon,
								htmlspecialchars($app['title'])
							);
		}

		$html = <<<HTML
<div class="font14"><span class="txt1 rTime">3月21日</span><strong>{$friend_link}</strong> 是你游戏中的好友，系统已经把{$gender}自动加为你的好友啦</div>
<h2 class="pd10">你们一起玩的应用</h2>
<div class="app playApp">
		{$app_list}
	<div class="clear"></div>
</div>
<p>
	<a class="button buttonBig" href="/relation" target="_blank"><span>查看我的好友</span></a>
	<a class="button buttonBig" href="{$friend_url}" target="_blank"><span>访问{$gender}的主页</span></a>
</p>
HTML;


		return $html;

	} else {
		return '';
	}
}



